home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 029a / pdsrt321.zip / PDSORT.DOC < prev    next >
Text File  |  1991-09-07  |  18KB  |  361 lines

  1.                                    PDSORT
  2.                    A Public Domain External Sort Program
  3.  
  4. Author:   Don A. Williams
  5. Version:  3.2.1                                                         |
  6. Date:     September 7, 1991                                             |
  7.  
  8.    ****************************  NOTICE!  **************************
  9.    *   Contrary to the current trend  in  MS-DOS  software  this   *
  10.    *   program,  for  whatever  it is worth,  is NOT copyrighted   *
  11.    *   (with the exception of the runtime library  from  Borland   *
  12.    *   International's  Turbo  C)!  The program,  in whole or in   *
  13.    *   part,  may be used freely in any fashion  or  environment   *
  14.    *   desired.  If  you  find this program to be useful to you,   *
  15.    *   do NOT send any contribution to the author;  in the words   *
  16.    *   of  Rick  Conn,   'Enjoy!'  However,   if  you  make  any   *
  17.    *   improvements,  I would enjoy  receiving  a  copy  of  the   *
  18.    *   modified  source.  I  can  be reached,  usually within 24   *
  19.    *   hours,  by  messages  on  any  of  the  Phoenix  systems,   *
  20.    *   particularly:                                               *
  21.    *                                                               *
  22.    *               Technoids Anonymous     [PCBOARD]               *
  23.    *                   (602) 899-4876   300/1200/2400 bps          *
  24.    *                                                               *
  25.    *   All can be reached through PC Pursuit.                      *
  26.    *                                                               *
  27.    *                                                               *
  28.    *   Every  effort has been made to avoid error and moderately   *
  29.    *   extensive testing has been  performed  on  this  program,   *
  30.    *   however, the author does not warrant it to be fit for any   *
  31.    *   purpose  or  to  be  free  from  error  and disclaims any   *
  32.    *   liability for actual or any other damage arising from the   *
  33.    *   use of this program.                                        *
  34.    *                                                               *
  35.    *    Don A. Williams                                            *
  36.    *    3913 W. Solano Dr. N.                                      *
  37.    *    Phoenix, AZ  85019                                         *
  38.    *    (602) 841-5333                                             *
  39.    *****************************************************************
  40.  
  41. PDSORT is a fully public domain external sort  program,  i.e.  it  can 
  42. sort  files  that  are too big to be wholly contained in memory.  This
  43. version of PDSORT contains a fully public domain  implentation  of  an
  44. iterative version of qsort(), PDQSORT.C, that is fully compatible with
  45. the  ANSI  C  standard run time qsort().  The qsort() routine supplied
  46. with most of the C compilers is a  recursive  implementation  that  is
  47. slower  and  requires  a  great  deal  more  stack  than the iterative
  48. version.  The length of the file that  can  be  sorted  by  PDSORT  is
  49. limited  only by the available disk space,  however,  you must have at 
  50. least twice as much free space as the length of the file to be  sorted 
  51. -  PDSORT uses an intermediate file the size of the input file and the 
  52. sorted output file will be the same size as the input file.  
  53.  
  54.  
  55. USAGE: 
  56.  
  57. There are three forms for executing PDSORT:                           
  58.  
  59.     pdsort in_file out_file [option] [max_rec_length] [key_spec ....]
  60.  
  61. and:
  62.  
  63.     pdsort -[option] [max_rec_length] [key_spec...] <in_file >out_file
  64.  
  65. and:                                                                  
  66.                                                                       
  67.     pdsort <in_file >out_file                                         
  68.                                                                       
  69. In the first form,  the input_file specification can be  any  standard 
  70. MS-DOS  file  specification including full path specifications but may 
  71. NOT contain "wild cards".  The output_file specification may  also  be 
  72. any  standard  MS-DOS  file specification not containing "wild cards".  
  73. The input_file and output_file names may be  the  same  but,  in  this 
  74. case,  the input_file will be destroyed by PDSORT  by  overwriting  it 
  75. with   the   output  file.    If  no  max_record_length  argument   is 
  76. specified,   PDSORT will use a default of 256  characters/record.   No 
  77. records in the input file may exceed  the maximum record  length.   If  
  78. a  record  that exceeds  the  maximum  record  length  is  detected in 
  79. the input file, PDSORT will issue a message identifying the record and 
  80. will terminate. 
  81.  
  82. In the second form, PDSORT executes as a "filter", reading and sorting 
  83. standard input to produce  standard  output,  both  of  which  may  be 
  84. redirected.  
  85.  
  86.  
  87. In  the  third form,  PDSORT also executes as a "filter",  reading and
  88. sorting standard input to produce standard output,  both of which  may
  89. be  redirected.  The  difference between the second form and the third
  90. form is that the third form uses the default maximum  record  size  of
  91. 256 characters/record and the default sort key of the entire record.  
  92.  
  93. Options:
  94.  
  95. The only options supported by version 2.1.3 of PDSORT are: 
  96.  
  97.     -      A single '-',  delimited by  blanks,  instructs  PDSORT  to 
  98.            operate  as a filter,  taking its input from standard input 
  99.            and sending its output to standard output.  
  100.  
  101.     -tpath The '-t' option allows the user to specify the path for the 
  102.            intermediate file created by PDSORT.  If no  such  path  is 
  103.            specified,  PDSORT  will use the path of the output file as 
  104.            the path of the intermediate file.  If the "filter"  option 
  105.            is selected and no intermediate file path is specified, the 
  106.            intermediate file will be created in the current directory.  
  107.            There  must  be NO blanks between the "-t"   and  the  path 
  108.            specification. 
  109.  
  110.     -o     The  '-o'  option  will  suppress all messages except error 
  111.            messages.                                                  
  112.  
  113.     -k     Use a "key sort"  instead of sorting the entire input file.
  114.            If  this option is specified,  PDSORT will extract the  key
  115.            fields  from the input file for sorting.   This option  can
  116.            alleviate  the  problem  caused by  the  fact  the  PDSORT,
  117.            currently,  has only a single merge pass.   Large files  of
  118.            long  records  can produce too many runs to be sorted in  a
  119.            single   merge  pass,   particularly  in   reduced   memory
  120.            environments  such  as  executing  PDSORT  out  of  another
  121.            program.  The "key sort" is NOT the complete answer to this
  122.            problem and  a  future  version  of  PDSORT  will support a
  123.            multi÷pass merge.
  124.  
  125.  
  126. Key Specification:
  127.  
  128. There  may  be  as  many keys specified as you wish.  The file will be 
  129. sorted on the keys in the order in  which  they  are  specified.  Each 
  130. key_spec has one of the following two formats: 
  131.  
  132.     b:l:[field_options]
  133.  
  134. or:
  135.  
  136.     b-e:[field_options]
  137.  
  138. where:
  139.  
  140.     b - Specifies  the  beginning  character  position of the field in 
  141.         decimal;  i.e to sort a field that is in columns 10 through 17 
  142.         of the record, b would be 10.
  143.     l - Specifies the length of the field in characters; i.e to sort a 
  144.         field that is in columns 10 through 17 of the record,  l would 
  145.         be 8 - 10:8[:options].
  146.     e - Specifies the  ending  character  position  of  the  field  in 
  147.         decimal,  inclusive;  i.e to sort a file that is in characters 
  148.         10 through 17 of the record with  this  format  of  the  field 
  149.         specifier would require the e be 17 - 10-17[:options].
  150.  
  151. Field Options:
  152.  
  153.     a - Specifies  that  the  sort on this field is to be in ascending 
  154.         order,  the default if no field option is specified  for  this 
  155.         field.  
  156.  
  157.     d - Specifies  that  the sort on this field is to be in descending 
  158.         order.  
  159.  
  160.     c - Specifies that the sort on this field is to be case sensitive; 
  161.         i.e.  the  word  Abscess"  would  sort  lower  that  the  word 
  162.         "abscess".  A  case  sensitive  sort  is the default if none 
  163.         is specified.  
  164.  
  165.     i - Specifies  that  the  sort  on  this  field  is  to  be   case 
  166.         insensitive.  
  167.  
  168.     c - Specifies that this field is ASCII character data, the default 
  169.         if  not  specified.  Since  PDSORT  2.0.0  supports only ASCII 
  170.         character fields, this option if only for upward compatibility 
  171.         with future version of PDSORT that  may  support  other  field 
  172.         types such as integer (numeric).  
  173.  
  174.  
  175.  
  176. Error Levels                                                         
  177.                                                                      
  178. If PDSORT terminates due to an error condition, it will set the MS-DOS
  179. ERRORLEVEL as follows:                                                
  180.                                                                       
  181.      1 - Invalid command argument or option.                          
  182.      2 - Unable  to open the specified input file.  Possibly incorrect
  183.          file name.                                                   
  184.      3 - Input/Output error on input file.                            
  185.      4 - A record in the input file exceeds the maximum length        
  186.      5 - Insufficient space on output disk.                           
  187.      6 - Insufficient space on intermediate disk.                     
  188.      7 - Unable to create output file.                                
  189.      8 - Input/Output error on output file.                           
  190.      9 - Unable to create intermediate file.                          
  191.     10 - Input/Output error on intermediate file.                    
  192.     11 - Reopen failure!                                             
  193.     12 - Insufficient memory.                                        
  194.                                                                      
  195. On normal termination, the ERRORLEVEL will be set to 0.              
  196.  
  197.  
  198.  
  199. Examples:
  200.  
  201. Assume  a  file,  named  FILELIST,  that contains a list of file name, 
  202. sizes, date/times, and paths, such as can be created by NUFIND: 
  203.  
  204.     a----w           27,974 90-04-30  6:30 c:\acelst.430
  205.     a----w           28,196 90-05-21  5:05 c:\acelst.521
  206.     a----w           28,238 90-05-25  5:41 c:\acelst.525
  207.     a----w           26,705 90-05-25  5:39 c:\acelst.lst
  208.     a----w          128,537 90-05-25  5:41 c:\acelst.zip
  209.     a----w              904 90-05-23  4:33 c:\autoexec.bat
  210.     a----w           35,840 89-06-30 12:16 c:\command.com
  211.     a----w               46 89-08-20  3:53 c:\config.cal
  212.     a----w              284 90-05-21 19:52 c:\config.sys
  213.     a----w            2,128 90-05-23  4:32 c:\configur.dat
  214.     ------           39,385 89-07-14 12:00 c:\drbdos.sys
  215.     ------           18,304 89-06-30 12:16 c:\drbios.sys
  216.     ---sh-            4,096 90-03-18 13:22 c:\drildr.sys
  217.     a----w              167 89-10-11  7:56 c:\dsas.cmd
  218.     a----w              102 86-11-04  9:14 c:\ed.def
  219.     a----w           50,326 86-10-02 21:34 c:\ed.hlp
  220.     a----w            3,362 86-06-09 13:10 c:\fakey.com
  221.     a----w                0 90-05-23  7:54 c:\ftf.dat
  222.     a----w           12,275 85-06-16 18:12 c:\helpe.def
  223.     a----w               79 89-05-17  5:02 c:\indent.pro
  224.     a----w            7,122 90-01-15  1:00 c:\lineend.com
  225.     a----w            1,060 90-05-25  9:40 c:\mark0
  226.     a--sh-               41 90-05-25  9:40 c:\mirorsav.fil
  227.     a-----           41,472 90-05-25  9:40 c:\mirror.bak
  228.     a-----           41,472 90-05-25  9:40 c:\mirror.fil
  229.     a----w              237 90-02-06  5:09 c:\model
  230.     a----w           12,432 87-03-10 13:34 c:\mouse.sys
  231.     a----w            2,507 87-10-21 13:45 c:\nansi.sys
  232.     a----w              251 87-07-16 18:06 c:\newkbios.com
  233.     a----w            6,094 89-11-21 15:03 c:\no101.com
  234.     a----w            2,836 90-05-03  7:21 c:\phone.dir
  235.     a----w            2,670 89-12-01 17:00 c:\phones
  236.     a----w            2,010 90-03-18 11:14 c:\pushdir.stk
  237.     a----w               90 89-09-05  3:29 c:\ruler.def
  238.     a----w            1,465 87-04-22 10:38 c:\ruler.prt
  239.     a----w           53,632 85-05-03 14:09 c:\sk.hlp
  240.     a----w           33,611 86-12-05  9:21 c:\skn.com
  241.     a----w           18,825 90-01-15  1:00 c:\synonym.com
  242.     a----w            1,610 90-05-13 16:15 c:\synonym.def
  243.     a----w           14,426 90-05-19 17:38 c:\utils
  244.     a----w            1,060 90-05-25 12:17 c:\mark1
  245.  
  246. The file path name begins in column 40 and  extends  through  80,  the 
  247. file size is in columns 15 through 23,  inclusive, the file date is in 
  248. columns 25 through 32,  inclusive,  and the file time is in columns 34 
  249. through 39, inclusive.  
  250.  
  251. A PDSORT command to sort this list so that the largest files are first 
  252. and files of equal size are in name order would require the  following 
  253. command: 
  254.  
  255.     pdsort filelist fileout 80 15-23:d 44-80
  256.  
  257. giving the following list in the file FILEOUT:
  258.  
  259.     a----w          128,537 90-05-25  5:41 c:\acelst.zip
  260.     a----w           53,632 85-05-03 14:09 c:\sk.hlp
  261.     a----w           50,326 86-10-02 21:34 c:\ed.hlp
  262.     a-----           41,472 90-05-25  9:40 c:\mirror.bak
  263.     a-----           41,472 90-05-25  9:40 c:\mirror.fil
  264.     ------           39,385 89-07-14 12:00 c:\drbdos.sys
  265.     a----w           35,840 89-06-30 12:16 c:\command.com
  266.     a----w           33,611 86-12-05  9:21 c:\skn.com
  267.     a----w           28,238 90-05-25  5:41 c:\acelst.525
  268.     a----w           28,196 90-05-21  5:05 c:\acelst.521
  269.     a----w           27,974 90-04-30  6:30 c:\acelst.430
  270.     a----w           26,705 90-05-25  5:39 c:\acelst.lst
  271.     a----w           18,825 90-01-15  1:00 c:\synonym.com
  272.     ------           18,304 89-06-30 12:16 c:\drbios.sys
  273.     a----w           14,426 90-05-19 17:38 c:\utils
  274.     a----w           12,432 87-03-10 13:34 c:\mouse.sys
  275.     a----w           12,275 85-06-16 18:12 c:\helpe.def
  276.     a----w            7,122 90-01-15  1:00 c:\lineend.com
  277.     a----w            6,094 89-11-21 15:03 c:\no101.com
  278.     ---sh-            4,096 90-03-18 13:22 c:\drildr.sys
  279.     a----w            3,362 86-06-09 13:10 c:\fakey.com
  280.     a----w            2,836 90-05-03  7:21 c:\phone.dir
  281.     a----w            2,670 89-12-01 17:00 c:\phones
  282.     a----w            2,507 87-10-21 13:45 c:\nansi.sys
  283.     a----w            2,128 90-05-23  4:32 c:\configur.dat
  284.     a----w            2,010 90-03-18 11:14 c:\pushdir.stk
  285.     a----w            1,610 90-05-13 16:15 c:\synonym.def
  286.     a----w            1,465 87-04-22 10:38 c:\ruler.prt
  287.     a----w            1,060 90-05-25  9:40 c:\mark0
  288.     a----w            1,060 90-05-25 12:17 c:\mark1
  289.     a----w              904 90-05-23  4:33 c:\autoexec.bat
  290.     a----w              284 90-05-21 19:52 c:\config.sys
  291.     a----w              251 87-07-16 18:06 c:\newkbios.com
  292.     a----w              237 90-02-06  5:09 c:\model
  293.     a----w              167 89-10-11  7:56 c:\dsas.cmd
  294.     a----w              102 86-11-04  9:14 c:\ed.def
  295.     a----w               90 89-09-05  3:29 c:\ruler.def
  296.     a----w               79 89-05-17  5:02 c:\indent.pro
  297.     a----w               46 89-08-20  3:53 c:\config.cal
  298.     a--sh-               41 90-05-25  9:40 c:\mirorsav.fil
  299.     a----w                0 90-05-23  7:54 c:\ftf.dat
  300.  
  301. The same sort could be accomplished by the command:
  302.  
  303.     pdsort - 80 15-23:d 40-80 <filelist >fileout
  304.  
  305.  
  306. Now suppose that you wanted the most recently modified or  created  files 
  307. first.  The following command would do that:
  308.  
  309.     pdsort filelist fileout 80 25-32:d 34-39:d 40-80
  310.  
  311. giving the following list in FILEOUT:
  312.  
  313.     a----w            1,060 90-05-25 12:17 c:\mark1
  314.     a----w            1,060 90-05-25  9:40 c:\mark0
  315.     a--sh-               41 90-05-25  9:40 c:\mirorsav.fil
  316.     a-----           41,472 90-05-25  9:40 c:\mirror.bak
  317.     a-----           41,472 90-05-25  9:40 c:\mirror.fil
  318.     a----w           28,238 90-05-25  5:41 c:\acelst.525
  319.     a----w          128,537 90-05-25  5:41 c:\acelst.zip
  320.     a----w           26,705 90-05-25  5:39 c:\acelst.lst
  321.     a----w                0 90-05-23  7:54 c:\ftf.dat
  322.     a----w              904 90-05-23  4:33 c:\autoexec.bat
  323.     a----w            2,128 90-05-23  4:32 c:\configur.dat
  324.     a----w              284 90-05-21 19:52 c:\config.sys
  325.     a----w           28,196 90-05-21  5:05 c:\acelst.521
  326.     a----w           14,426 90-05-19 17:38 c:\utils
  327.     a----w            1,610 90-05-13 16:15 c:\synonym.def
  328.     a----w            2,836 90-05-03  7:21 c:\phone.dir
  329.     a----w           27,974 90-04-30  6:30 c:\acelst.430
  330.     ---sh-            4,096 90-03-18 13:22 c:\drildr.sys
  331.     a----w            2,010 90-03-18 11:14 c:\pushdir.stk
  332.     a----w              237 90-02-06  5:09 c:\model
  333.     a----w            7,122 90-01-15  1:00 c:\lineend.com
  334.     a----w           18,825 90-01-15  1:00 c:\synonym.com
  335.     a----w            2,670 89-12-01 17:00 c:\phones
  336.     a----w            6,094 89-11-21 15:03 c:\no101.com
  337.     a----w              167 89-10-11  7:56 c:\dsas.cmd
  338.     a----w               90 89-09-05  3:29 c:\ruler.def
  339.     a----w               46 89-08-20  3:53 c:\config.cal
  340.     ------           39,385 89-07-14 12:00 c:\drbdos.sys
  341.     a----w           35,840 89-06-30 12:16 c:\command.com
  342.     ------           18,304 89-06-30 12:16 c:\drbios.sys
  343.     a----w               79 89-05-17  5:02 c:\indent.pro
  344.     a----w            2,507 87-10-21 13:45 c:\nansi.sys
  345.     a----w              251 87-07-16 18:06 c:\newkbios.com
  346.     a----w            1,465 87-04-22 10:38 c:\ruler.prt
  347.     a----w           12,432 87-03-10 13:34 c:\mouse.sys
  348.     a----w           33,611 86-12-05  9:21 c:\skn.com
  349.     a----w              102 86-11-04  9:14 c:\ed.def
  350.     a----w           50,326 86-10-02 21:34 c:\ed.hlp
  351.     a----w            3,362 86-06-09 13:10 c:\fakey.com
  352.     a----w           12,275 85-06-16 18:12 c:\helpe.def
  353.     a----w           53,632 85-05-03 14:09 c:\sk.hlp
  354.  
  355. Again,  the same sort could have been accomplished  by  the  following 
  356. command: 
  357.  
  358.     pdsort - 25-32:d 34-39:d 40-80 <filelist >fileout
  359.  
  360.  
  361.